


import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JProgressBar;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Jose Luis Orta
 */
public class StepAccionProgreso extends TimerTask {
    private Timer t;
    private Progreso p;
    private JProgressBar jpb;
    private NumberFormat formatter;
    private Runnable accionFin;
    public StepAccionProgreso(Timer t,Progreso p, JProgressBar jpb, Runnable accionFin){
        this.t=t;
        this.p=p;
        this.jpb = jpb;
        this.accionFin = accionFin;
        formatter = new DecimalFormat("0,00 %");
    }
    @Override
    public void run() {
       jpb.setValue((int)p.getPc());
       jpb.setString(formatter.format(p.getPc()));
       if (p.isFin() || p.getN()==p.getX()) {
           t.cancel();
           jpb.setValue(100);
           jpb.setString("100 %");
           try {
               accionFin.run();
           } catch (Exception ex){
           
           }
       }
    }
    
}
